﻿using CPPEI.ETL.DataServiceInterface;
using CPPEI.WebApi;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using ENT = CPPEI.ETL.Domain.Entities;
using MOD = CPPEI.ETL.Domain.Models;
using SER = CPPEI.ETL.Domain.Services;

namespace CPPEI.ETL.WebApi.PubDS
{
    [CPPEI.WebApi.AuthPostAction("PubDS", "UpdateDataSource", "1.0")]
    public class UpdateDataSourceAction : BaseAction<UpdateDataSourceParams, UpdateDataSourceResult>
    {
        protected override ActionResult<UpdateDataSourceResult> OnExecute(ActionContext context, 
            SysParameters sysParameters,
            UpdateDataSourceParams opParams)
        {
            SER.PubSourceService service = new SER.PubSourceService();
            ServiceResult serResult = service.Update(opParams.Id, opParams.Type, opParams.Value, opParams.Description, opParams.ParameterSettings);
            if(serResult.IsSuccess)
            {
                UpdateDataSourceResult result = new UpdateDataSourceResult();
                return new ActionResult<UpdateDataSourceResult>(result);
            }
            else
            {
                return new ActionResult<UpdateDataSourceResult>(serResult.IsSuccess, serResult.ErrorCode, serResult.Message, null);
            }
        }
    }

    public class UpdateDataSourceParams
    {
        public Guid Id { get; set; }

        /// <summary>
        /// 描述
        /// </summary>
        public string Description { get; set; }

        public string Value { get; set; }

        /// <summary>
        /// 1:sql语句,2:存储过程
        /// </summary>
        public int Type { get; set; }

        /// <summary>
        /// name,type(CodeType),description
        /// </summary>
        public string ParameterSettings { get; set; }
    }

    public class UpdateDataSourceResult
    {
    }
}
